package userchannellogic

import (
	"context"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/model/config"
	modelConfig "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/schema/config"

	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/model/user/channel"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"
	"github.com/zeromicro/go-zero/core/logx"
)

type UserBankInfoPageLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserBankInfoPageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserBankInfoPageLogic {
	return &UserBankInfoPageLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserBankInfoPageLogic) UserBankInfoPage(in *rpc.UserBankInfoPageRequest) (*rpc.UserBankInfoPageResponse, error) {
	res, err := channel.NewBankModel(l.ctx, l.svcCtx.Db).UserBankInfoPage(in)
	if err != nil {
		return nil, err
	}

	configBankList := config.NewBankModel(l.ctx, l.svcCtx.Db).GetAllConfigBank()
	var bankMap = make(map[int64]modelConfig.ConfigBank)
	for _, item := range configBankList {
		bankMap[item.ID] = item
	}

	for i := 0; i < len(res.DataList); i++ {
		res.DataList[i].BankName = bankMap[res.DataList[i].BankId].BankName
	}
	return res, err
}
